/**
 * Project Name:JingZhenGu
 * File Name:CarTypeAdapter.java
 * Package Name:com.gc.jingzhengu.adapter
 * Date:2014-5-26上午11:28:41
 * Copyright (c) 2014, wangyd523@gmail.com All Rights Reserved.
 */

package com.jzg.jcptadmin.adpter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.data.vo.Style;

import java.util.List;

/**
 * ClassName:CarTypeAdapter <br/>
 * Function: 车型年度款式列表适配器. <br/>
 * Date: 2014-5-26 上午11:28:41 <br/>
 *
 * @author 汪渝栋
 * @see
 * @since JDK 1.6
 */
public class StyleCategoryAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<Style> list;
    private List<String> groupNames;

    public StyleCategoryAdapter(Context context, List<Style> list,
                                List<String> groupNames) {
        super();
        inflater = LayoutInflater.from(context);
        this.list = list;
        this.groupNames = groupNames;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        if (!TextUtils.isEmpty(list.get(position).getNowMsrp())) {

            return list.get(position).getName();
        }
        return list.get(position).getName();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean isEnabled(int position) {
        if (groupNames.contains(getItem(position))) {
            return false;
        }
        return super.isEnabled(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (groupNames.contains(getItem(position))) {
            view = inflater.inflate(R.layout.addexam_list_item_tag, null);
        } else {
            view = inflater.inflate(R.layout.addstyle_item, null);
            view.setBackgroundColor(list.get(position).getItemColor());
        }

        TextView text = (TextView) view
                .findViewById(R.id.addexam_list_item_text);
//        wyd-----估爷流程中右厂商指导价字段显示，目前这个项目设计图中没有相关设计，为了防止后期有变动
//        先把这段代码注释掉，布局文件中的相关TextView已经删除，避免增加界面负担，以后如果有增加
//        可以从估爷项目中辅助相关布局，如果不增加则可以和MoelCategroyAdapter合并，公用一个adpter
//        TextView priceText = (TextView) view
//                .findViewById(R.id.addexam_list_item_price);
//        TextView priceHint = (TextView) view
//                .findViewById(R.id.addexam_list_item_priceHint);
//        if (!TextUtils.isEmpty(list.get(position).getNowMsrp())) {
//            priceText.setVisibility(View.VISIBLE);
//            priceHint.setVisibility(View.VISIBLE);
//            priceText.setText(list.get(position).getNowMsrp() + "万元");
//        }
        text.setText((CharSequence) getItem(position));
        text.setTextColor(list.get(position).getFontColor());
        return view;
    }
}
